//
//  YWNewCirculationButtonCell.m
//  maintain
//
//  Created by 郑想 on 16/7/29.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWNewCirculationButtonCell.h"
#import "UIColor+CustomColors.h"
#import "Masonry.h"
#import "UILabel+AttributedText.h"
#import "YWMacro.h"

@interface YWNewCirculationButtonCell()
@property (nonatomic, strong) UIButton *circulationButton;
@end

@implementation YWNewCirculationButtonCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    YWNewCirculationButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:YWNewCirculationButtonCellIdentifier];
    if (cell == nil) {
        cell = [[YWNewCirculationButtonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:YWNewCirculationButtonCellIdentifier];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        [self setUpSubviews];
        self.contentView.backgroundColor = [UIColor customBackgroudColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsMake(0, SCREEN_WIDTH, 0, 0);
    }
    return self;
}

- (void) setUpSubviews {
    UIView *superview = self.contentView;
    
    UIEdgeInsets padding = UIEdgeInsetsMake(10, 20, 10, 20);
    [self.circulationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(superview).insets(padding);
        make.height.mas_equalTo(kButtonH);
    }];
}

- (UIButton *)circulationButton{
    if (!_circulationButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.backgroundColor = [UIColor customBlueColor];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.layer.borderColor = [UIColor customBlueColor].CGColor;
        button.layer.borderWidth = 1.0;
        button.clipsToBounds = YES;
        button.layer.cornerRadius = 4.0;
        button.titleLabel.font = KTitleFont;
        [button addTarget:self action:@selector(clickCirculationButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        _circulationButton = button;
        [self.contentView addSubview:_circulationButton];
    }
    return _circulationButton;
}

- (void)clickCirculationButtonEvent:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(clickCirculationButtonEventWithTitle:)]) {
        [self.delegate clickCirculationButtonEventWithTitle:sender.titleLabel.text];
    }
}

- (void)setButtonTitle:(NSString *)buttonTitle{
    [_circulationButton setTitle:buttonTitle?:@"" forState:UIControlStateNormal];
//    if ([buttonTitle isEqualToString:@"分配和撤回报障"]) {
//        [self.circulationButton mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.mas_equalTo(kButtonH*2);
//        }];
//    }else{
//        [self.circulationButton mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.mas_equalTo(kButtonH);
//        }];
//    }
}

@end
